package com.yunhe.policyfulfillment.policyful.controller;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.policyful.model.*;
import com.yunhe.policyfulfillment.policyful.service.AppealSatisfactionService;
import com.yunhe.policyfulfillment.policyful.service.AppealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @ClassName: StatisticsController
 * @Description:
 * @author: GongDaCheng
 * @Date: 17:24 2021/10/8
 */
@Api(value = "Statistics", description = "统计分析", tags = {"统计分析"})
@RestController
@RequestMapping(value = "/statistics")
public class StatisticsController {

    @Autowired
    private AppealSatisfactionService appealSatisfactionService;

    @Autowired
    private AppealService appealService;

    @ApiOperation("满意度统计")
    @PostMapping("/satisfactionStatistics")
    public ResponseEntity<ResultObject<List<SatisfactionStatistics>>> satisfactionStatistics(@RequestBody DateCondition dateCondition) {
        PageResult result = appealSatisfactionService.satisfactionStatistics(dateCondition);
        return new ResponseEntity<>(new ResultObject(result), HttpStatus.OK);
    }

    /**
     * timeType:年度:"01"
     *          月度:"02"
     * */
    @ApiOperation("诉求分布图")
    @GetMapping("/appealDistribution")
    public ResponseEntity<ResultObject<List<OrgAppealStatistic>>> appealDistribution(@RequestParam(value = "timeType",required = true) String timeType){
        List<OrgAppealStatistic> orgAppealStatistics = appealService.appealDistribution(timeType);
        return new ResponseEntity<>(new ResultObject(orgAppealStatistics), HttpStatus.OK);
    }
    /**
     * timeType:年度:"01"
     *          月度:"02"
     *
     * appealState:总量:""
     *             待处理:"02"(包括待处理("02")和待分派("01"))
     *             已处理:"03"(包括已处理("03")和中止("04"))
     * */
    @ApiOperation("诉求处理报表")
    @GetMapping("/appealProcessingReport")
    public ResponseEntity<ResultObject<AppealProcessingReportVO>> appealProcessingReport(@RequestParam(value = "timeType",required = true) String timeType,
                                                                                         @RequestParam(value = "appealState",required = false) String appealState){
        AppealProcessingReportVO appealProcessingReportVO = appealService.appealProcessingReport(timeType, appealState);
        return new ResponseEntity<>(new ResultObject(appealProcessingReportVO), HttpStatus.OK);
    }

    /**
     * timeType:近3个月:"01"
     *          近6个月:"02"
     *          近12个月:"03"
     * */
    @ApiOperation("处理时效分布图")
    @GetMapping("/appealProcessingEfficiency")
    public ResponseEntity<ResultObject<List<AppealProcessingEfficiency>>> appealProcessingEfficiency(@RequestParam(value = "timeType",required = true) String timeType) throws ParseException {
        List<AppealProcessingEfficiency> appealProcessingEfficiencies = appealService.appealProcessingEfficiency(timeType);
        return new ResponseEntity<>(new ResultObject(appealProcessingEfficiencies), HttpStatus.OK);
    }

}
